/**
 * 
 */
package com.java.test.user.service.impl;

import com.java.test.timer.MessagePushTimer;
import com.java.test.user.dto.DrawingChannelInfo;
import com.java.test.user.dto.DrawingTypeInfo;
import com.java.test.user.mapper.DrawingChannelMapper;
import com.java.test.user.mapper.DrawingTypeMapper;
import com.java.test.user.service.DrawingMangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Administrator
 *
 */
@Service
public class DrawingMangeServiceImpl implements DrawingMangeService {

	@Autowired
	DrawingTypeMapper drawingTypeMapper;

	@Autowired
	DrawingChannelMapper drawingChannelMapper;

	@Value("${file.img.down.url}")
	private String fielUrl;

	@Override
	public List<DrawingTypeInfo> selectdrawingList() {
		return drawingTypeMapper.selectdrawingList();
	}

	@Override
	public int insertdrawingInfo(DrawingTypeInfo info) {
		if (info != null) {
			info.setAddTime(LocalDateTime.now());
		}
		return drawingTypeMapper.insertdrawingInfo(info);
	}

	@Override
	public DrawingTypeInfo selectdrawingtypeInfobyId(DrawingTypeInfo info) {
		return drawingTypeMapper.selectdrawingtypeInfobyId(info);
	}

	@Override
	public int updatedrawingInfo(DrawingTypeInfo info) {
		return drawingTypeMapper.updatedrawingInfo(info);
	}

	@Override
	public int updatedrawingsortInfo(DrawingTypeInfo info) {
		return drawingTypeMapper.updatedrawingsortInfo(info);
	}

	@Override
	public int deletedrawingInfo(DrawingTypeInfo info) {
		return drawingTypeMapper.deletedrawingInfo(info);
	}

	@Override
	public List<DrawingChannelInfo> selectdrawingchannelList(DrawingChannelInfo info) {

		List<DrawingChannelInfo> list = drawingChannelMapper.selectdrawingchannelList(info);

		if (list != null && list.size() > 0) {
			list.forEach(b -> {
				b.setImgUrl(fielUrl + b.getImgUrl());
				int typeid = b.getDrawingTypeId();
				DrawingTypeInfo obj = new DrawingTypeInfo();
				obj.setId(typeid);
				DrawingTypeInfo tinfo = drawingTypeMapper.selectdrawingtypeInfobyId(obj);
				if (tinfo != null) {
					b.setDrawingTypeName(tinfo.getTypeName());
				}
			});
		}
		return list;
	}

	@Override
	public int insertdrawingchannelInfo(DrawingChannelInfo info) {
		if (info != null) {
			info.setAddTime(LocalDateTime.now());
		}
		int i = drawingChannelMapper.insertdrawingchannelInfo(info);
		if(i>0){
			MessagePushTimer.drawingChannelCLQ.offer("drawingChannelPush");
		}
		return i;
	}

	@Override
	public DrawingChannelInfo selectdrawingchannelInfobyId(DrawingChannelInfo info) {
		DrawingChannelInfo b  =drawingChannelMapper.selectdrawingchannelInfobyId(info);
		if(b!=null) {
			b.setImgUrl(fielUrl + b.getImgUrl());
		}
		
		return b;
	}

	@Override
	public int updatedrawingchannelInfo(DrawingChannelInfo info) {
		int i = drawingChannelMapper.updatedrawingchannelInfo(info);
		if(i>0){
			MessagePushTimer.drawingChannelCLQ.offer("drawingChannelPush");
		}
		return i;
	}

	@Override
	public int updatedrawingchannelsortInfo(DrawingChannelInfo info) {
		int i = drawingChannelMapper.updatedrawingchannelsortInfo(info);
		if(i>0){
			MessagePushTimer.drawingChannelCLQ.offer("drawingChannelPush");
		}
		return i;
	}

	@Override
	public int deletedrawingchannelInfo(DrawingChannelInfo info) {
		int i = drawingChannelMapper.deletedrawingchannelInfo(info);
		if(i>0){
			MessagePushTimer.drawingChannelCLQ.offer("drawingChannelPush");
		}
		return i;
	}

	@Override
	public int selectdrawingchanbyTypeId(int typeid) {
		return drawingChannelMapper.selectdrawingchanbyTypeId(typeid);
	}
}
